import { Component, Input, ViewChild, ElementRef ,OnInit} from '@angular/core';
import { Router } from '@angular/router';
// 引入Parse第三方库
import * as Parse from "parse"
(Parse as any).serverURL = "http://metapunk.cn:9999/parse"
Parse.initialize("dev")
@Component({
  selector: 'app-comp-img-slider',
  templateUrl: './comp-img-slider.component.html',
  styleUrls: ['./comp-img-slider.component.scss']
})
export class CompImgSliderComponent  implements OnInit{
  @ViewChild('slider') slider!: ElementRef;

  imgUrl: string = '';
  link: string = '';
  caption: string = '';
  currentIndex: number = 0;
  timer: any;

  sliders: any[] = [
    {},{},{},{},
   ];

  

  ngOnDestroy() {
    this.stopSlideshow();
  }

  startSlideshow() {
    this.timer = setInterval(() => {
      this.nextSlide();
    }, 3000);
  }

  stopSlideshow() {
    clearInterval(this.timer);
  }

  navigateToSlide(index: number) {
    this.currentIndex = index;
    this.slider.nativeElement.scrollLeft = index * window.innerWidth;
    this.stopSlideshow();
    this.startSlideshow();
  }

  nextSlide() {
    if (this.currentIndex === this.sliders.length - 1) {
      this.navigateToSlide(0);
    } else {
      this.navigateToSlide(this.currentIndex + 1);
    }
  }

  async ngOnInit(): Promise<void> {
    this.startSlideshow();
    this.getsliderByID()
  }


  //跳转详情页
  goodList:any
async getsliderByID(){
  let query = new Parse.Query("goods")
    let slist = await query.find()
this.goodList = slist
    console.log(slist)
}


sliderList:any
  //进入详情页面
  goDetail(item:any) {
    console.log(item+"itemslider");
    
     this.router.navigate(["./intelligent-shopping/detail"],{
        queryParams:{
        id:item?.id
  }
     })
  }
  constructor(private router:Router){
  
  }

}
